package com.blb.educourseservice.controller;

import com.blb.common.entity.Course;
import com.blb.common.util.ResponseResult;
import com.blb.educourseservice.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CourseController {

    @Autowired
    private CourseService courseService;

    /**
     * 查询所有课程
     * @return
     */
    @GetMapping("/courses")
    public ResponseResult<List<Course>> getAllCourses(){
        List<Course> courses = courseService.getAllCourses();
        return ResponseResult.ok(courses);
    }

    @GetMapping("/course/{id}")
    public Course getCourseById(@PathVariable Long id){
        return courseService.getCourseById(id);
    }

    @RequestMapping("/course/sales")
    public Course addCourseSales(@RequestParam Long id,
                                 @RequestParam(required = false,defaultValue = "1") Integer sales){
        return courseService.addCourseSales(id,sales);
    }
}
